package il.ac.tau.dbcourse.gui;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.Properties;

public class MyProperties{
	static Properties defaultProps;
	static Properties applicationProps;
	static Boolean DEBUG=true;
	public void setProperty(String key, String value)
	{
		applicationProps.setProperty( key,  value);
		saveProps();
	}
	public String getProperty(String key)
	{
		return applicationProps.getProperty( key);
	}
	
	public void init()
	{
		// create and load default properties
		defaultProps = new Properties();
		FileInputStream in;
		try {
			in = new FileInputStream("defaultProperties");
			defaultProps.load(in);
			in.close();
			
		} catch (FileNotFoundException e) {
			if (DEBUG)
				System.out.println("didnt find default properties file");
			
		}
		  catch (IOException e) {
			e.printStackTrace();
		  }
		  try{
			in = new FileInputStream("appProperties");
			applicationProps = new Properties(defaultProps);
			applicationProps.load(in);
			in.close();
		} catch (FileNotFoundException e) {
			applicationProps = new Properties(defaultProps);
			
		}
		  catch (IOException e) {
			e.printStackTrace();
		  }
	
	}
	
	public void saveProps()
	{
		FileOutputStream out;
		try {
			out = new FileOutputStream("appProperties");
			applicationProps.store(out, "---No Comment---");
			out.close();
			
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		 
	}
	
	
}

	

